package com.meiyu.live.tv.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.meiyu.live.R;

/**
 * Created by zbl on 2016/12/9.
 * 工具view，美颜按钮
 */
public class ToolsView extends FrameLayout implements View.OnClickListener {

    public interface OnToolButtonClickListener {
        void onClickBeauty();
    }

    private Context context;

    private OnToolButtonClickListener listener;

    private View layout_tools;
    private ImageView btn_hide;
    private View btn_beauty;

    private boolean isShow = false;

    public ToolsView(Context context) {
        super(context);
        init(context);
    }

    public ToolsView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        this.context = context;
        LayoutInflater.from(context).inflate(R.layout.view_tools, this);
        layout_tools = findViewById(R.id.layout_tools);
        btn_hide = (ImageView) findViewById(R.id.btn_hide);
        btn_hide.setOnClickListener(this);
        btn_beauty = findViewById(R.id.btn_beauty);
        btn_beauty.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view == btn_hide) {
            show(!isShow);
        } else if (view == btn_beauty) {
            if (listener != null) {
                listener.onClickBeauty();
            }
        }
    }

    public void show(boolean isShow) {
        if (isShow) {
            layout_tools.setVisibility(VISIBLE);
            btn_hide.setImageResource(R.drawable.play_push_icon);
        } else {
            layout_tools.setVisibility(GONE);
            btn_hide.setImageResource(R.drawable.play_pull_icon);
        }
        this.isShow = isShow;
    }

    public void setListener(OnToolButtonClickListener listener) {
        this.listener = listener;
    }
}
